import cn.yunhe.dao.IUserDao;
import cn.yunhe.entity.User;
import cn.yunhe.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

public class Demo {
    SqlSession sqlSession = null;
    IUserDao userDao = null;
    @Test
    public void Demo1() {
        sqlSession = SqlSessionFactoryUtil.getSqlSession();
        userDao = sqlSession.getMapper(IUserDao.class);
        User user = new User("user","123","13737245307","王中国");
        int user1 = userDao.regUser(user);
        if (user1>0){
            System.out.println("成功");
            sqlSession.commit();
        }else {
            System.out.println("失败");
            sqlSession.rollback();
        }
    }

    @Test
    public void Demo2() {
        sqlSession = SqlSessionFactoryUtil.getSqlSession();
        userDao = sqlSession.getMapper(IUserDao.class);
        User user = new User("user","123");
        User user1 = userDao.userLogin(user);
        if (user1!=null){
            System.out.println(user1.getName()+","+user1.getPassword());
        }else {
            sqlSession.rollback();

        }
    }

    @Test
    public void Demo3() {
        sqlSession = SqlSessionFactoryUtil.getSqlSession();
        userDao = sqlSession.getMapper(IUserDao.class);
        User user1 = userDao.userIsAdmin("user");
        if (user1.getIsadmin()==0){
            System.out.println("是用户");
        }else {
            System.out.println("是管理员");

        }
    }

    @Test
    public void Demo4() {
        sqlSession = SqlSessionFactoryUtil.getSqlSession();
        userDao = sqlSession.getMapper(IUserDao.class);
        User user1 = userDao.getAllUserByName("user");
        if (user1!=null){
            System.out.println("111");
        }else {
            System.out.println("222");

        }
    }

}
